package com.ha.controller.admin;

import com.ha.dto.GarbagePageDTO;
import com.ha.dto.UserPageDTO;
import com.ha.dto.UserRegisterDTO;
import com.ha.entity.User;
import com.ha.result.PageResult;
import com.ha.result.Result;
import com.ha.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: UserController
 * Package: com.ha.controller.admin
 * Description:
 *
 * @Author 那啥啥
 * @Create 2024/4/22  20:35
 * @Version 1.0
 */
@RestController("adminUserController")
@RequestMapping("/admin/user")
@Api(tags = "用户接口")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 用户分也查询
     * @param userPageDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("用户分页查询")
    public Result<PageResult> page(UserPageDTO userPageDTO){
        log.info("垃圾分页查询参数为 ：{}",userPageDTO);
        PageResult pageResult = userService.pageQuery(userPageDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增用户
     * @param userRegisterDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增用户")
    public Result addUser(@RequestBody UserRegisterDTO userRegisterDTO){
        log.info("新增员工{}",userRegisterDTO);
         userService.addUser(userRegisterDTO);
         return Result.success();
    }
    /**
     * 更新用户
     * @param userRegisterDTO
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("更新用户")
    public Result updaye(@RequestBody UserRegisterDTO userRegisterDTO){
        log.info("更新用户{}",userRegisterDTO);
        userService.updateUser(userRegisterDTO);
        return Result.success();
    }

    /**
     * 删除用户
     */
    @PostMapping("/delete/{deleted}")
    @ApiOperation("删除用户逻辑删除")
    public Result delete(@PathVariable Integer deleted ,Long id){
        log.info("删除员工账号：{}，{}",deleted,id);
        userService.delete(deleted,id);
        return Result.success();
    }

    /**
     * 修改用户回显数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("修改回显数据")
    public Result<User> getById(@PathVariable Long id){

        User user = userService.getById(id);
        return Result.success(user);
    }

}
